package com.yuanlrc.base.entity.admin;

import com.yuanlrc.base.annotion.ValidateEntity;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;

/**
 * 图书的实体类
 */
@Entity
@Table(name="ylrc_book")
@EntityListeners(AuditingEntityListener.class)
public class Book  extends BaseEntity {
//    private static final long serialVersionUID = 1L;

    public static final int BOOK_ACTIVE = 1; //借阅
    public static final int BOOK_NORMAL = 0; //不可借阅

    @ValidateEntity(required=true,requiredLeng=true,minLength=4,maxLength=18,errorRequiredMsg="图书名不能为空!",errorMinLengthMsg="图书名长度需大于4!",errorMaxLengthMsg="用户名长度不能大于18!")
    @Column(name="book_name",nullable=false,length=18,unique=true)
    private String bookName;//图书名

    @ValidateEntity(required=true,requiredLeng=true,minLength=1,maxLength=32,errorRequiredMsg="作者不能为空！",errorMinLengthMsg="作者长度需大于1!",errorMaxLengthMsg="作者长度不能大于32!")
    @Column(name="author",nullable=false,length=32)
    private String author;//作者

    @ValidateEntity(required=true,requiredLeng=true,minLength=1,maxLength=5,errorRequiredMsg="价格不能为空！",errorMinLengthMsg="价格长度需大于1!",errorMaxLengthMsg="价格长度不能大于5!")
    @Column(name="price",nullable=false,length=32)
    private String price;//单价

    @ValidateEntity(required=true,requiredLeng=true,minLength=5,maxLength=20,errorRequiredMsg="出版社不能为空！",errorMinLengthMsg="出版社长度需大于5!",errorMaxLengthMsg="出版社长度不能大于20!")
    @Column(name="press",nullable=false,length=32)
    private String press;//单价

    @ManyToOne
    @JoinColumn(name="category_id")
    private BookCategory  category;//所属二级分类

    @ManyToOne
    @JoinColumn(name="parent_id")
    private  BookCategory  parent;//所属分类


    @Column(name="state",nullable=false,length=32)
    private    int    state = BOOK_ACTIVE;  //状态

    @Column(name="num",nullable=false,length=32)
    private   Integer num=0; //数量

    @Column(name="cannum",nullable=false,length=32)
    private   Integer  cannum; //可借数量

    @Column(name="introduce",nullable=false,length=999)
     private   String   introduce; //介绍

    public Book(String bookName, String author,String price,String press, BookCategory category, BookCategory parent, int state, Integer num, Integer cannum, String introduce) {
        this.bookName = bookName;
        this.price = price;
        this.press = press;
        this.author = author;
        this.category = category;
        this.parent = parent;
        this.state = state;
        this.num = num;
        this.cannum = cannum;
        this.introduce = introduce;
    }

    public Book() {
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getPrice() {
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }

    public String getPress() {
        return press;
    }

    public void setPress(String press) {
        this.press = press;
    }

    public BookCategory getCategory() {
        return category;
    }

    public void setCategory(BookCategory category) {
        this.category = category;
    }

    public BookCategory getParent() {
        return parent;
    }

    public void setParent(BookCategory parent) {
        this.parent = parent;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public Integer getNum() {
        return num;
    }

    public void setNum(Integer num) {
        this.num = num;
    }

    public Integer getCannum() {
        return cannum;
    }

    public void setCannum(Integer cannum) {
        this.cannum = cannum;
    }

    public String getIntroduce() {
        return introduce;
    }

    public void setIntroduce(String introduce) {
        this.introduce = introduce;
    }

    @Override
    public String toString() {
        return "Book{" +
                "bookName='" + bookName + '\'' +
                ", author='" + author + '\'' +
                ", price='" + price + '\'' +
                ", press='" + press + '\'' +
                ", category=" + category +
                ", parent=" + parent +
                ", state=" + state +
                ", num=" + num +
                ", cannum=" + cannum +
                ", introduce='" + introduce + '\'' +
                '}';
    }
}
